package com.hope.onlinestudy.fragment.message

import android.support.v7.widget.LinearLayoutManager
import com.hope.onlinestudy.R
import com.hope.onlinestudy.adapter.MessageAdapter
import com.hope.onlinestudy.model.MessageModel
import com.hope.onlinestudy.mvp.MVPBaseFragment
import com.jcodecraeer.xrecyclerview.XRecyclerView
import kotlinx.android.synthetic.main.layout_xrecyclerview.*

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */
class MessageFragment : MVPBaseFragment<MessageContract.View, MessagePresenter>(),
    XRecyclerView.LoadingListener,
    MessageContract.View {
    private var pageIndex: Int = 1
    private val adapter: MessageAdapter<MessageModel> by lazy { MessageAdapter<MessageModel>() }

    override fun initView(): Int {
        return R.layout.layout_xrecyclerview
    }

    override fun bindData() {
        rcvList.layoutManager = LinearLayoutManager(activity)
        rcvList.adapter = adapter
        rcvList.setLoadingListener(this)

        mPresenter?.getMsg()
    }

    override fun lazyLoad() {
    }

    override fun onLoadMore() {
        pageIndex++
        mPresenter?.getMsg(pageIndex)
    }

    override fun onRefresh() {
        pageIndex = 1
        mPresenter?.clearData()
        mPresenter?.getMsg()
    }

    override fun msgList(data: ArrayList<MessageModel>) {
        adapter.setDataEntityList(data)
    }

    override fun reflashCommpand() {
        rcvList.refreshComplete()
        rcvList.loadMoreComplete()
    }
}